home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / dbms_mag / 9103 / cea1.mar < prev    next >
Text File  |  1991-01-28  |  2KB  |  80 lines

  1.  
  2. /*****************************************************************
  3. *  MyGroups.C
  4. *  written by Kathy Cea, Platinum Software Int'l.
  5. *
  6. *  Lists all the groups to which the user belongs.
  7. *
  8. *  Calling Syntax:
  9. *     MyGroups
  10. *
  11. *  Compiled in Turbo C 2.0 with NetWare C function calls
  12. *****************************************************************/
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <nit.h>
  17. #include <niterror.h>
  18. #define NO 0
  19. #define YES 1
  20.  
  21. main() {
  22.     WORD ConnectNumber;
  23.     BYTE loginTime[7];
  24.     long objectId;
  25.     WORD objectType;
  26.     char objectName[48],
  27.          groupName[48];
  28.     BYTE propertyValue[128];
  29.     BYTE moreSegs,
  30.          propertyFlag;
  31.     int segNum;
  32.     BYTE temp[3];
  33.     BYTE holdobjId[9];
  34.     char *endptr;
  35.     int i,j,done;
  36.  
  37.     segNum = 1;
  38.     moreSegs = 255;
  39.  
  40.     /* Get the current connection number */
  41.     ConnectNumber = GetConnectionNumber();
  42.  
  43.     /* Get the Object Name and Object Type */
  44.     GetConnectionInformation(ConnectNumber, objectName,
  45.             &objectType, &objectId, loginTime);
  46.  
  47.     printf("Groups I'm in:\n");
  48.  
  49.     /* Read the GROUP_I'M_IN property set until no more groups */
  50.     while (moreSegs) {
  51.        ReadPropertyValue(objectName, OT_USER, "GROUPS_I'M_IN", segNum,
  52.              propertyValue, &moreSegs, &propertyFlag);
  53.  
  54.         segNum++;
  55.         /* Convert each 4-byte value into a long Object ID */
  56.         i = 0;
  57.         temp[2] = '\0';
  58.         holdobjId[0] = '\0';
  59.         done = NO;
  60.         while (i < 128 && !done) {
  61.             for (j=0; j < 4; j++) {
  62.                 sprintf(temp, "%02x", propertyValue[i]);
  63.                 temp[2] = '\0';
  64.                 strcat(holdobjId, temp);
  65.                 i++;
  66.             } /* for */
  67.             objectId = strtoul(holdobjId, &endptr, 16);
  68.             if (objectId == 0)
  69.                 done = YES;
  70.             else {
  71.                 /* Now that we have the Object ID, get the Group Name */
  72.                 GetBinderyObjectName(objectId, groupName, &objectType);
  73.                 printf("%s\n",groupName);
  74.                 holdobjId[0] = '\0';
  75.              } /* else */
  76.         } /* while (i < 128) */
  77.     } /* while (moreSegs) */
  78. } /* main */
  79.  
  80.